<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label class="layui-form-label">项目名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" value="<{if isset($data)}><{$data->name}><{/if}>"
                           lay-verify="required" placeholder="请输入 项目名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">项目介绍</label>
                <div class="layui-input-block">
                    <input type="text" name="description" value="<{if isset($data)}><{$data->description}><{/if}>"
                           lay-verify="required" placeholder="请输入 介绍" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">源IP</label>
                <div class="layui-input-block">
                    <input type="text" name="sources" value="<{if isset($data)}><{$data->sources}><{/if}>"
                           lay-verify="required" placeholder="源IP" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-block">
                    <input type="text" id="laydate-start" name="start_time"
                           value="<{if isset($data)}><{$data->start_time}><{/if}>"
                           lay-verify="required" placeholder="项目开始时间" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">到期时间</label>
                <div class="layui-input-block">
                    <input type="text" id="laydate-end" name="end_time"
                           value="<{if isset($data)}><{$data->end_time}><{/if}>"
                           lay-verify="required" placeholder="项目到期时间" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <input type="button" lay-submit lay-filter="form-submit" id="form-submit"
                       value="确认">
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'element', 'laydate'], function () {
        var $ = layui.$
            , form = layui.form
            , element = layui.element;
        var laydate = layui.laydate;


        //开始日期
        var insStart = laydate.render({
            elem: '#laydate-start'
            , min: 0
            , type: 'datetime'
            , min: '2018-7-1'
            , done: function (value, date) {
                //更新结束日期的最小日期
                insEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                insEnd.config.elem[0].focus();
            }
        });

        //结束日期
        var insEnd = laydate.render({
            elem: '#laydate-end'
            , min: 0
            , type: 'datetime'
            , done: function (value, date) {
                //更新开始日期的最大日期
                insStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        form.render();
        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;
        //监听提交
        form.on('submit(form-submit)', function (data) {
            var field = data.field; //获取提交的字段

            //提交 Ajax 成功后，关闭当前弹层并重载表格
            //$.ajax({});
            $.post('/<{$module}>/<{$controller}>/<{$action}>/id/<{if isset($data)}><{$data->id}><{/if}>?isajax=1&', field, function (res) {
                if (res.code == 0) {
                    //ok
                    layui.table.reload('table-page'); //重载表格
                    layer.close(parentIndex); //再执行关闭
                } else {
                    layer.msg(res.msg);
                }
            }, 'json')
        });
    })
</script>